<template>
  <div id="contacts">
    <div class="head">
      <div class="logo">速讯</div>
      <div class="hello">
        hello，<span class="name" @click="jump">moko</span>
        <div class="img" @click="jump">
          <img src="/static/img/contact.jpg">
        </div>
      </div>
    </div>
    <div class="content">
      <div class="lside">
        <ul>
          <li :class="{'active': clickId == 0}">
            <router-link to="/contacts">
              <i class="fa fa-address-book-o"></i>通讯录
            </router-link>
          </li>
          <li :class="{'active': clickId == 1}">
            <router-link to="/contacts/add">
              <i class="fa fa-heart"></i>添加联系人
            </router-link>
          </li>
          <li :class="{'active': clickId == 2}">
            <router-link to="/contacts/center">
              <i class="fa fa-user-o"></i>个人中心
            </router-link>
          </li>
        </ul>
        <div class="quit" @click="quit">
          <i class="fa fa-cog"></i>退出登录
        </div>
      </div>
      <div class="rside">
        <router-view
          :books="books"
          :personal="personal">
        </router-view>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: 'contacts',
  data() {
    return {
      clickId: 0,
      path: {
        '/contacts': 0,
        '/contacts/add': 1,
        '/contacts/center': 2
      }
    }
  },
  methods: {
    quit() {
      if(confirm('确定要退出登录吗？')) {
        this.$store.dispatch('signOut')
        this.$router.replace('/home/login')
      }
    },
    jump() {
      this.clickId = 2
      this.$router.push('/contacts/center')
    }
  },
  created() {
    const val = this.$route.path
    this.clickId = this.path[val]

    this.$store.dispatch('userInit')
  },
  watch: {
    '$route.path'(newVal, oldVal) {
      this.clickId = this.path[newVal]
    }
  },
  computed: mapState({
      books: state => state.Contact.books,
      personal: state => state.Contact.personal
  })
}
</script>

<style lang="less" scoped>
#contacts {
  .head {
    width: 100%;
    height: 90px;
    line-height: 90px;
    padding: 0 30px;
    background-image: url(/static/img/bg.png);
    background-size: cover;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 10;

    .logo {
      font-size: 50px;
      color: #0f88eb;
    }
    .hello {
      font-size: 20px;
      display: flex;
      align-items: center;
      .name {
        font-weight: 550;
        margin-right: 10px;
        max-width: 118px;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        cursor: pointer;
      }
      .img {
        width: 75px;
        height: 75px;
        border-radius: 50%;
        overflow: hidden;
        cursor: pointer;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
  @media screen and (max-width: 480px){
    .head {
      padding: 0 5px;
      .logo {
        font-size: 30px;
      }
    }
  }
  .content {
    .lside {
      width: 30%;
      // max-width: 300px;
      height: 90%;
      background-color: #eee;
      padding: 3px;
      position: fixed;
      top: 90px;
      left: 0;
      z-index: 5;
      ul {
        li {
          height: 50px;
          line-height: 50px;
          background-color: #fff;
          margin-bottom: 2px;
          font-size: 17px;
          padding: 0 5px;
          padding-left: 10%;
          text-overflow: ellipsis;
          overflow: hidden;
          
          a {
            width: 100%;
            height: 100%;
            display: inline-block;
            color: #555;
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
            text-decoration: none;
            i {
              margin-right: 12px;
            }
          }
        }
        li.active {
          background-color: #0f88eb;
          a {
            color: #fff;
          }
        }
        @media screen and (max-width: 320px){
          li {
            font-size: 13px;
          }
        }
      }
      .quit {
        font-size: 16px;
        position: absolute;
        bottom: 41px;
        right: 16px;
        cursor: pointer;
        i {
          margin-right: 3px;
        }
      }
      @media screen and (max-width: 320px){
        .quit {
          font-size: 13px;
        }
      }
    }
    .rside {
      width: 100%;
      height: 100%;
      padding-left: 30%;
      padding-top: 90px;
      position: absolute;
    }
    @media screen and (min-width: 1200px) {
      .lside {
        width: 300px;
      }
      .rside {
        padding-left: 300px;
      }
    }
  }
}

</style>